﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class problem
    {
        public static dynamic getDSAutoPid(int eid)
        {
            var sql = new Sql.SqlDataContext();
            var pids = from p in sql.DSProblem
                       where p.eid == eid
                       orderby p.pid
                       select p.pid;
            if (pids.Count() == 0) return new
                {
                    success = true,
                    pid = 0
                };
            var first = pids.FirstOrDefault();
            pids = pids.Skip(1);
            foreach (var p in pids)
            {
                if (p - first > 1) break;
                first = p;
            }
            return new
            {
                success = true,
                pid = first + 1
            };
        }
    }
}
